package com.qn.web.qnwebbase.service.impl;

import com.qn.web.qnwebbase.common.vo.UserInfo;
import com.qn.web.qnwebbase.service.ILoginService;
import org.springframework.stereotype.Service;
import qn.common.service.IRedisCache;

import javax.annotation.Resource;

@Service
public class LoginServiceImpl implements ILoginService {

    @Resource
    IRedisCache redisCache;

    private static String keyPre = "LoginService:UlId:";

    @Override
    public boolean isLogin(String ulId) {
        Object o = redisCache.get(keyPre + ulId);
        if(o==null)
            return false;

        return true;
    }

    @Override
    public UserInfo getUserLoginInfo(String ulId) {
        Object o = redisCache.get(keyPre + ulId);
        if (o == null)
            return null;

        return (UserInfo) redisCache.get(keyPre + ulId);
    }

    @Override
    public void login(UserInfo userInfo) {
        redisCache.put(keyPre + userInfo.getUlId(), userInfo, 24 * 60 * 60);
    }

    @Override
    public void logOut(String ulId) {
        redisCache.remove(keyPre + ulId);
    }
}
